import {reqDetailList,reqAddOrUpdataShopCart} from '@/api'
const state ={
    detailList:{}
}
const mutations = {
    GETDETAILLIST(state,detailList){
        state.detailList = detailList
    },
};
const actions = {
    async getDetailList({commit},skuId){
          let result = await reqDetailList(skuId);
          if(result.code == 200){
              commit('GETDETAILLIST',result.data)
          }
      },
      async addShopcart({commit},{skuId,skuNum}){
        let result = await reqAddOrUpdataShopCart(skuId,skuNum);
        console.log(skuId,skuNum);
        
        if(result.code == 200){
            return "ok" 
        }else{
            return Promise .reject(new Error('faile'))
        }
    },
      
  };
const getters = {
    categoryView(state){
        return state.detailList.categoryView||{}
    },
    spuSaleAttrList(state){
        return state.detailList.spuSaleAttrList
    },
    skuInfo(state){
        return state.detailList.skuInfo||{}
    }
};
export default {
    state,
    mutations,
    actions,
    getters
}